package com.safe.ele.controller;
import com.safe.ele.config.RedisKeyConfig;
import com.safe.ele.dto.ProdectDto;
import com.safe.ele.entity.IProduct;
import com.safe.ele.service.intf.IProductService;
import com.safe.ele.util.RedissonUtil;
import com.safe.ele.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Set;

/**
 * @program: springboot
 * @description: 十一组后端源码
 * @author: Feri(十一组)
 * @create: 2021-01-09 17:39:00
 */

@RestController
@RequestMapping("api/iProduct/")
@Api(tags = "实现IProduct各种操作")
public class IProductController{
    /*
    *注入业务逻辑层对象*/
    @Autowired
    private IProductService service;
    /*
    * 新增内容*/
    @ApiOperation(value = "实现新增",notes = "实现新增")
    @PostMapping("IProduct.save.do")
    public R save(@RequestBody IProduct iProduct){
       return service.save(iProduct);
    }
    /*
    * 查询 所有数据*/
    @ApiOperation(value = "实现全部查询",notes = "实现全部查询")
    @GetMapping("IProduct.all.do")
    public R  all(){
        Set<ProdectDto> set=(Set<ProdectDto>)RedissonUtil.getSet(RedisKeyConfig.INDEX_KEY);
        if(set==null){
            service.queryAll();
              Set<ProdectDto> set1=(Set<ProdectDto>)RedissonUtil.getSet(RedisKeyConfig.INDEX_KEY);
            return R.ok(set1);
        }else {
            return R.ok(set);
        }

    }
    /*
     * 根据ID查询数据*/
     @ApiOperation(value = "根据ID查询数据",notes = "根据ID查询数据")
     @GetMapping("IProduct.selectById.do")
     public R selectById(IProduct iProduct){

       return service.selectById(iProduct);
     }

    /*
     * 删除内容*/
     @ApiOperation(value = "实现删除",notes = "实现删除")
     @PostMapping("IProduct.del.do")
     public R del(@RequestBody IProduct iProduct){
        return service.DelAll(iProduct);
     }

     /*
     * 跟新内容*/
     @ApiOperation(value = "实现跟新",notes = "实现跟新")
     @PostMapping("IProduct.updateById.do")
     public R updateById(@RequestBody IProduct iProduct){
         return service.updateById(iProduct);
      }

     /*
     * 模糊查询*/
     @ApiOperation(value = "实现模糊查询",notes = "实现模糊查询")
     @GetMapping("IProduct.selectMhcx.do")
     public R selectMhcx(String pname,Integer typeid){
         List<ProdectDto> iProducts = service.selectMhcx(pname, typeid);
         return R.ok(iProducts);
       }

     /*
     * 批量删除*/
     @ApiOperation(value = "实现批量删除",notes = "实现批量删除")
     @PostMapping("IProduct.deleteByIds.do")
     public R deleteByIds(@RequestBody IProduct iProduct,String ids){
         return service.deleteByIds(iProduct,ids);
      }

}